package com.sushuo.api.controller;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.sushuo.api.service.ProductService;
import com.sushuo.api.util.RedisTest;
import com.sushuo.base.bean.Product;

@RequestMapping(value = "/testctrl")
@RestController
public class TestController {
    
    private final Logger logger = LoggerFactory.getLogger(TestController.class);
    
    @Autowired
    private ProductService productService;
    
    @Autowired
    private RedisTest redisTest;
    
    /**
     * 测试 url: http://localhost:8091/testctrl/test?telephone=123&verifyCode=098
     * @param telephone
     * @param verifyCode
     * @return
     */
    @RequestMapping(value = "/test", produces = {"application/json;charset=UTF-8"})
    public Map<String, Object> test(String telephone, String verifyCode) {
        logger.error("log--------{}","error");
        logger.warn("log--------{}", "warn");
        logger.info("log--------{}", "info");
        logger.debug("log--------{}", "debug");
        logger.trace("log---------{}", "trace");
        
        Map<String, Object> map = new HashMap<>();
        map.put("date", new Date());
        map.put("telephone", telephone);
        map.put("verifyCode", verifyCode);
        return map;
    }
    
    @RequestMapping(value = "/test/product", produces = {"application/json;charset=UTF-8"})
    public Product getByProductId(Integer id){
        return productService.getById(id);
    }
    
    @RequestMapping(value = "/test/redis", produces = {"application/json;charset=UTF-8"})
    public String redisTest(){
        return redisTest.setGetString();
    }
}
